﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NIP.ControllerInterface;
using System.Threading;
namespace HandEye
{
    public partial class Form1 : Form
    {
        UsbcController controller;
        public Form1()
        {
            InitializeComponent();
            //Controller
            controller = new UsbcController();
//            controllerObject.HomingStatusChanged += new EventHandler<ControllerInterface.HomingStatusEventArgs>(HomingStatusChanged_Handler);
            controller.Initialization(1, 92);
            Thread.Sleep(2000);
            controller.Control((byte)'&', true);
        }


        private void initBtn_Click(object sender, EventArgs e)
        {
            controller.Initialization(1, 92);
            Thread.Sleep(2000);
            controller.Control((byte)'&', true);
        }

        private void absCoorBtn_Click(object sender, EventArgs e)
        {
            var pos = new Position();

            pos.XYZ = new int[USBC.TotalAxes] { 343355, 4790, 114503, -84587, 20967, 0, 0, 0 };
            controller.MoveToPosition(pos, PointType.AbsoluteXYZCoordinateA);




           // string vectorName = "moffff";
           // int[] vectorArray1 = { 339144, 118277, 194789, -84587, 20967 };
           // int[] vectorArray2 = { 343355, 108790, 114503, -84587, 20967 };
           // int[] vectorArray3 = { -95676, 307271, 268582, -84623, 21003 };

           // controller.DefineVector((byte)'A', vectorName, 3);
            
           // controller.Teach(vectorName, 1, vectorArray1, 5, -32766);
           // Console.WriteLine("pass");
           // controller.Teach(vectorName, 2, vectorArray2, 5, -32766);
           // Console.WriteLine("pass");
           // controller.Teach(vectorName, 3, vectorArray3, 5, -32766);
           // Console.WriteLine("pass");
           // //Thread implementation
           // //controller.MoveLinear(vectorName, 1, null, 0);
           // Thread.Sleep(10000);
           // controller.OpenGripper();
           // Thread.Sleep(3000);
           // controller.MoveLinear(vectorName, 2, null, 0);
           // Thread.Sleep(10000);
           // controller.CloseGripper();
           // Thread.Sleep(3000);
           //// controller.MoveLinear(vectorName, 1, null, 0);
           // Thread.Sleep(10000);
           // controller.MoveLinear(vectorName, 3, null, 0);
           // Thread.Sleep(10000);
           // controller.OpenGripper();

            return;
        }

        private void manualBtn_Click_1(object sender, EventArgs e)
        {
            ManualControl manualControl = new ManualControl();
            //manualControl.Owner = this;
            manualControl.Show();
        }

        private void homeBtn_Click(object sender, EventArgs e)
        {
            controller.Home((byte)Axis.All);
            return;
        }

        private void getPosBtn_Click(object sender, EventArgs e)
        {
            var pos = controller.GetCurrentPosition();
            if (pos == null)
            {
                Console.WriteLine("Error getting possition");
            }
            else
            {
                absCoorX.Text = pos.XYZ[0].ToString();
                absCoorY.Text = pos.XYZ[1].ToString();
                absCoorZ.Text = pos.XYZ[2].ToString();
            }
            return;

        }



    }
}
